//
//  ZSNetworkTool.m
//  online
//
//  Created by guoxiaoshuang on 2018/7/31.
//  Copyright © 2018年  ysyy. All rights reserved.
//

#import "ZSNetworkTool.h"

@implementation ZSNetworkTool
- (instancetype)init{
    if (self = [super init]) {
        
        NSURL *url = [NSURL URLWithString:BASEURLSTR];
        _manager = [[AFHTTPSessionManager manager]initWithBaseURL:url];
        //        _manager.requestSerializer = [AFJSONRequestSerializer serializer];
        _manager.responseSerializer = [AFHTTPResponseSerializer serializer];
        
        _manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/json", @"text/plain", @"text/html", nil];
        
    }
    return self;
}

#pragma mark - 实例化单例子
+ (instancetype)sharedTool{
    
    static ZSNetworkTool *instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance =  [[ZSNetworkTool alloc] init];
    });
    
     [instance checkNetworkStatus];
    return instance;
}



- (void)checkNetworkStatus {
//    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
//    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
//        switch (status) {
//            case AFNetworkReachabilityStatusUnknown:{
////                [AutoAlertView showMessage:@"您正处在未知网络环境"];
//                break;
//            }
//            case AFNetworkReachabilityStatusNotReachable:{
//                [AutoAlertView showMessage:@"网络断开连接"];
//                break;
//            }
//            case AFNetworkReachabilityStatusReachableViaWiFi:{
//                
//                break;
//            }
//            case AFNetworkReachabilityStatusReachableViaWWAN:{
//                //                [AutoAlertView showMessage:@"您正处在移动网络环境"];
//        
//                break;
//            }
//            default:
//                break;
//        }
//    }];
}



#pragma mark - 基础
- (void)requestWithType:(RequestType)type andUrl:(NSString *)url andParameters:(NSMutableDictionary*)params andTimeOut:(double)timeOut resultWithBlock:(result)finishBlock
{
    
    if(!url || [url length] == 0)
    {//如果传入的url为空,这时候
        finishBlock(NO,@"请求地址不能为空");
        return;
    }
    
    //设置超时时间
    _manager.requestSerializer.timeoutInterval = timeOut;
    //拼接URL
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",BASEURLSTR,url];
    NSLog(@"url%@",urlStr);
    
    
    NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey:ZSToken];
    if(token.length != 0 && ![url isEqualToString:@"/index/Nanjinliuhe/getService"] && ![url isEqualToString:@"/index/Nanjinliuhe/getSerDet"]){
        params[@"token"] = token;
    }
    
    
    NSLog(@"请求参数%@",params);

    if (type == GET) {
        _requestTask = [self.manager GET:urlStr parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
            finishBlock(YES,responseObject);
            
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
            finishBlock(NO, @"");
            NSLog(@"网络错误信息：%@",error);
            
        }];
        
    } else {
        
        if (params == nil)
        {
            finishBlock(NO,@"post请求->请传入参数");
            return;
        }
        
        _requestTask = [self.manager POST:urlStr parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
            finishBlock(YES, responseObject);
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
            finishBlock(NO, @"");
            NSLog(@"网络错误信息：%@",error);
        }];
        
    }
    
}

#pragma mark - 公开的接口
#pragma mark - 新闻接口
- (void)getNewsDataWithType:(int)type andPageno:(int)pageno resultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    dict[@"pageno"] = @(pageno);
    dict[@"type"] = @(type);
    dict[@"pagesize"] = @(10);
    
    [self requestWithType:GET andUrl:@"/index/Nanjinliuhe/getArticle" andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }else if (code == 201 ||code == 203 || code == 204){
                finishBlock(NO,result);
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}


#pragma mark - 新闻详情接口
- (void)getNewsDetailWithNewsId:(NSString *)newid resultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    dict[@"id"] = newid;
    
    [self requestWithType:GET andUrl:@"/index/Nanjinliuhe/getArtDetails" andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }else if (code == 201 ||code == 203 || code == 204){
                finishBlock(NO,result);
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}

#pragma mark - 招聘列表接口
- (void)getJobListWithPageno:(int)pageno resultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    dict[@"pageno"] = @(pageno);
    dict[@"pagesize"] = @(10);
    
    [self requestWithType:GET andUrl:@"/index/Nanjinliuhe/getRecruit" andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}


#pragma mark - 招聘详情接口
- (void)getJobDetailWithJobid:(NSString *)jobid resultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    dict[@"id"] = jobid;
    
    [self requestWithType:POST andUrl:@"/index/Nanjinliuhe/getRecDetails" andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}


#pragma mark - 房产列表接口
- (void)getBuildListWithPageno:(int)pageno district:(NSString *)district address:(NSString *)address area:(NSString *)area house:(NSString *)house total_price:(NSString *)total_price price:(NSString *)price andTitle:(NSString *)title resultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    dict[@"pageno"] = @(pageno);
    dict[@"pagesize"] = @(20);
    dict[@"district"] = district;
    dict[@"address"] = address;
    dict[@"area"] = area;
    dict[@"house"] = house;
    dict[@"total_price"] = total_price;
    dict[@"price"] = price;
    dict[@"title"] = title;
    
    [self requestWithType:GET andUrl:@"/index/Nanjinliuhe/getBuildList" andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}





#pragma mark - 房产详情接口
- (void)getBuildingDetailWithBuildId:(NSString *)buidId resultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    dict[@"id"] = buidId;
    
    [self requestWithType:GET andUrl:@"/index/Nanjinliuhe/getBuildDetails" andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}


#pragma mark - 交流列表接口
- (void)getInteractListWithPageno:(int)pageno resultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    dict[@"pageno"] = @(pageno);
    dict[@"pagesize"] = @(10);
    
    [self requestWithType:GET andUrl:@"/index/Nanjinliuhe/noteList" andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}


#pragma mark - 交流详情接口
- (void)getInteractNoteDetailWithNote_id:(NSString *)note_id resultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    dict[@"pageno"] = @(1);
    dict[@"pagesize"] = @(1);
    dict[@"note_id"] = note_id;
    
    [self requestWithType:POST andUrl:@"/index/Nanjinliuhe/notedetail" andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}


#pragma mark - 交流评论列表接口
- (void)getInteractNoteCommentListWithNote_id:(NSString *)note_id resultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    dict[@"pageno"] = @(1);
    dict[@"pagesize"] = @(100);
    dict[@"note_id"] = note_id;
    
    [self requestWithType:POST andUrl:@"/index/Nanjinliuhe/noteComments" andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}








#pragma mark - 反馈接口
- (void)commitFeedbackWithContent:(NSString *)content resultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    dict[@"content"] = content;
    
    [self requestWithType:POST andUrl:@"/index/Nanjinliuhe/feedback" andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}



#pragma mark - 收藏接口
- (void)addCollectWithBuildingId:(NSString *)bid type:(int)type andIs_cancel:(BOOL)is_cancel resultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    dict[@"bid"] = bid;
    dict[@"type"] = @(type);
    dict[@"is_cancel"] = @(is_cancel);
    
    [self requestWithType:POST andUrl:@"/index/Nanjinliuhe/addCollect" andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}


#pragma mark - 点赞接口
- (void)addPraiseWithNote_id:(NSString *)note_id andIs_cancel:(BOOL)is_cancel resultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    dict[@"note_id"] = note_id;
    dict[@"is_cancel"] = @(is_cancel);
    
    [self requestWithType:POST andUrl:@"/index/Nanjinliuhe/addPraise" andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}


#pragma mark - 评论接口
//pid 回复评论ID  非必传
//note_id 帖子ID
- (void)submitCommentWithNote_id:(NSString *)note_id content:(NSString *)content pid:(NSString *)pid resultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    dict[@"note_id"] = note_id;
    dict[@"content"] = content;
    dict[@"pid"] = pid;
    
    [self requestWithType:POST andUrl:@"/index/Nanjinliuhe/comment" andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}

#pragma mark - 我的评论接口
- (void)getMyCommentResultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    
    [self requestWithType:POST andUrl:@"/index/Nanjinliuhe/myComment" andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}

#pragma mark - 我的点赞接口
- (void)getMyPariseResultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    
    [self requestWithType:POST andUrl:@"/index/Nanjinliuhe/myPraise" andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}


#pragma mark - 我的收藏/通知接口
- (void)getMyCollectWithType:(int)type resultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    dict[@"type"] = @(type);
    [self requestWithType:POST andUrl:@"/index/Nanjinliuhe/myCollect" andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}


#pragma mark - 登录接口-----
- (void)loginWithPhone:(NSString *)phone andPwd:(NSString *)password resultWithBlock:(result)finishBlock
{
    NSMutableDictionary * dic = [NSMutableDictionary dictionaryWithObjectsAndKeys:phone,@"mobile",password,@"password", nil];
    
    NSLog(@"登录的参数%@",dic);
    
    [self requestWithType:POST andUrl:@"/index/Member/login" andParameters:dic andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            NSLog(@"登录的请求结果是%@",result);
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }
            else
            {
                finishBlock(NO,@"账号密码错误");
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}


#pragma mark - 注册接口
- (void)rergistWithMobile:(NSString *)mobile andPassword:(NSString *)password
                resultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    dict[@"mobile"] = mobile;
    dict[@"password"] =password;
    
    
    [self requestWithType:POST andUrl:@"/index/Member/register"  andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }else if (code == 203){
                finishBlock(NO,result[@"msg"]);
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}

#pragma mark - 忘记密码接口
- (void)fogertPasswordWithMobile:(NSString *)mobile code:(NSString *)code andPassword:(NSString *)password resultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    dict[@"mobile"] = mobile;
    dict[@"password"] =password;
    dict[@"code"] = code;
    
    [self requestWithType:POST andUrl:@"/index/Member/forgetpwd"  andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }else if (code == 203){
                finishBlock(NO,result[@"msg"]);
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}


#pragma mark - 个人资料接口
- (void)getMineInfoResultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    [self requestWithType:POST andUrl:@"/index/Member/info"  andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }else if (code == 201){
                finishBlock(NO,result);
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}


#pragma mark - 通知列表接口
- (void)getMyNoticeListResultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    [self requestWithType:POST andUrl:@"/index/Nanjinliuhe/noticeList"  andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];

            if (code == 200)
            {
                finishBlock(YES,result);
                
            }else if (code == 201){
                finishBlock(NO,result);
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}



#pragma mark - 通知详情接口
- (void)getMyNoticeDetailResultWithNoticeId:(NSString *)noticeId resultBlock:(result)finishBlock
{
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    dict[@"id"] = noticeId;
    [self requestWithType:POST andUrl:@"/index/Nanjinliuhe/notice"  andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }else if (code == 201){
                finishBlock(NO,result);
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}


#pragma mark - 服务列表接口
- (void)getServiceListWithType:(NSString *)type resultBlock:(result)finishBlock
{
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    dict[@"type"] = type;
    [self requestWithType:POST andUrl:@"/index/Nanjinliuhe/getService"  andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }else if (code == 201){
                finishBlock(NO,result);
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}


#pragma mark - 服务详情接口
- (void)getServiceDetailWithServiceId:(NSString *)serviceId resultBlock:(result)finishBlock
{
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    dict[@"id"] = serviceId;
    [self requestWithType:POST andUrl:@"/index/Nanjinliuhe/getSerDet" andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }else if (code == 201){
                finishBlock(NO,result);
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}


#pragma mark - 天气类型接口
- (void)getWeatherTypeResultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    [self requestWithType:POST andUrl:@"/index/Nanjinliuhe/weatherType"  andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }else if (code == 201){
                finishBlock(NO,result);
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}

#pragma mark - 天气列表接口
- (void)getWeatherListWithCityId:(NSString *)cityId resultBlock:(result)finishBlock
{
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    dict[@"type"] = cityId;
    dict[@"pageno"] = @(1);
    dict[@"pagesize"] = @(40);
    [self requestWithType:POST andUrl:@"/index/Nanjinliuhe/weatherList" andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }else if (code == 201){
                finishBlock(NO,result);
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}

- (void)submitChangePersonInfoWithUsername:(NSString *)username andBirthday:(NSString *)birthday sex:(NSString *)sex resultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    dict[@"username"] = username;
    dict[@"birthday"] = birthday;
    dict[@"sex"] = sex;

    [self requestWithType:POST andUrl:@"/index/Member/edit"  andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }else if (code == 202){
                finishBlock(NO,result[@"msg"]);
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}


#pragma mark - 个人资料接口
- (void)getUserInfoDataResultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    [self requestWithType:POST andUrl:@"/index/Member/info"  andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
                
            }else if (code == 201){
                finishBlock(NO,result);
            }
        }
        else
        {
            finishBlock(NO,@"请求失败");
        }
        
    }];
}

#pragma mark - 修改头像接口
- (void)commitChangeMyIconWithfiles:( NSData*)files resultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dic =  [NSMutableDictionary dictionary];
    NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey:ZSToken];
    dic[@"token"] = token;
    
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",BASEURLSTR,@"/index/Member/headimg"];
    
    [self.manager POST:urlStr parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        // 设置时间格式
        formatter.dateFormat  = @"yyyyMMddHHmmss";
        NSString *str  = [formatter stringFromDate:[NSDate date]];
        NSString *fileName  = [NSString stringWithFormat:@"%@.png", str];
        [formData appendPartWithFileData:files name:@"files" fileName:fileName mimeType:@"image/png"];
        
        
    } progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSError *error;
        
        NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:&error];
        
        NSInteger code = [result[@"status"] integerValue];
        
        if (code == 200){
            finishBlock(YES,result);
        }else{
            finishBlock(NO,result);
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        finishBlock(NO,@"请求失败");

    }];
    
}


#pragma mark - 交流添加接口
- (void)addInteractPostWithContent:(NSString *)content resultWithBlock:(result)finishBlock
{
    
    NSMutableDictionary * dict =  [NSMutableDictionary dictionary];
    dict[@"content"] = content;
   
    [self requestWithType:POST andUrl:@"/index/Nanjinliuhe/add" andParameters:dict andTimeOut:20 resultWithBlock:^(BOOL success, id responseData) {
        if (success)
        {
            NSError *error;
            
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
            
            NSInteger code = [result[@"status"] integerValue];
            
            if (code == 200)
            {
                finishBlock(YES,result);
     
            }else{
                finishBlock(NO,@"请求失败");
            }
        }
            
    }];
}




@end
